//
//  BaseUI.swift
//  zob
//
//  Created by A-Jay on 29/3/2017.
//  Copyright © 2017年 A-Jay. All rights reserved.
//

import UIKit
/**
 *  UILabel
 */
//MARK: - UILabel
extension UILabel {
    //把按钮直接不同属性的名字传进来，在这里我们传进来图片名字和标题
    class func creatLabel(color:String, font:CGFloat) -> UILabel {
        let label = UILabel()
        label.textColor = UIColor.hexStringToColor(hexString: color)
        label.font = UIFont.systemFont(ofSize: font)
        return label
    }
}

/**
 *  UIImageView
 */
//MARK: - UIImageView
extension UIImageView {
    //把按钮直接不同属性的名字传进来，在这里我们传进来图片名字和标题
    class func creatImageView() -> UIImageView {
        let imageView = UIImageView()
        return imageView
    }
}

/**
 *  UIButton相关的初始化方法
 */
//MARK: - UIButton
extension UIButton {
    
//    class func creatButton() -> UIButton {
//        let button = UIButton()
//        return button
//    }
    
    class func creatTitleButton(_ title: String, _ titleColor: String, _ font: CGFloat) -> UIButton {
        let button = UIButton()
        button.setTitle(title, for: .normal)
        button.setTitleColor(UIColor.hexStringToColor(hexString: titleColor), for: .normal)
        button.titleLabel?.font = UIFont.systemFont(ofSize: font)
        return button
    }
    
    class func creatTitleButton(_ title: String, _ titleColor: String,_ font: CGFloat, _ borderColor: String, _ borderWidth: CGFloat, _ cornerRadius: CGFloat, _ masksToBounds: Bool) -> UIButton {
        let button = UIButton.creatTitleButton(title, titleColor, titleColor, font, borderColor, borderWidth, cornerRadius, masksToBounds)
        return button
    }
    
    class func creatTitleButton(_ title: String, _ titleColor: String, _ titleColorSelected: String, _ font: CGFloat, _ borderColor: String, _ borderWidth: CGFloat, _ cornerRadius: CGFloat, _ masksToBounds: Bool) -> UIButton {
        let button = UIButton.creatTitleButton(title, title, title, titleColor, titleColor, titleColorSelected, font, borderColor, borderWidth, cornerRadius, masksToBounds)
        
        return button
    }
    
    class func creatTitleButton(_ title: String, _ titleHighlighed: String, _ titleSelected: String, _ titleColor: String, _ titleColorHighlighed: String, _ titleColorSelected: String, _ font: CGFloat, _ borderColor: String, _ borderWidth: CGFloat, _ cornerRadius: CGFloat, _ masksToBounds: Bool) -> UIButton {
        let button = UIButton()
        //文字相关
        button.setTitle(title, for: .normal)
        button.setTitle(titleHighlighed, for: .highlighted)
        button.setTitle(titleSelected, for: .selected)
        button.setTitleColor(UIColor.hexStringToColor(hexString: titleColor), for: .normal)
        button.setTitleColor(UIColor.hexStringToColor(hexString: titleColorHighlighed), for: .highlighted)
        button.setTitleColor(UIColor.hexStringToColor(hexString: titleColorSelected), for: .selected)
        button.titleLabel?.font = UIFont.systemFont(ofSize: font)
        
        //边框
        button.layer.borderColor = UIColor.hexStringToColor(hexString: borderColor).cgColor;
        button.layer.borderWidth = borderWidth;
        button.layer.cornerRadius = cornerRadius;
        button.layer.masksToBounds = masksToBounds;
        
        return button
    }
    
    /**
     *  图片button
     */
    class func creatImageButton(_ image: String,_ imageHighlighted: String, _ borderColor: String, _ borderWidth: CGFloat, _ cornerRadius: CGFloat, _ masksToBounds: Bool) -> UIButton {
        let button = UIButton()
        
        //图片相关
        button.setImage(UIImage(named: image), for: .normal)
        button.setImage(UIImage(named: imageHighlighted), for: .highlighted)
        
        //边框
        button.layer.borderColor = UIColor.hexStringToColor(hexString: borderColor).cgColor;
        button.layer.borderWidth = borderWidth;
        button.layer.cornerRadius = cornerRadius;
        button.layer.masksToBounds = masksToBounds;
        
        return button
    }
    
    /**
     *  图文详细
     */
    class func creatButton(_ title: String, _ titleHighlighed: String, _ titleSelected: String, _ titleColor: String, _ titleColorHighlighed: String, _ titleColorSelected: String, _ font: CGFloat,_ image: String,_ imageHighlighted: String, _ borderColor: String, _ borderWidth: CGFloat, _ cornerRadius: CGFloat, _ masksToBounds: Bool) -> UIButton {
        let button = UIButton()
        //文字相关
        button.setTitle(title, for: .normal)
        button.setTitle(titleHighlighed, for: .highlighted)
        button.setTitle(titleSelected, for: .selected)
        button.setTitleColor(UIColor.hexStringToColor(hexString: titleColor), for: .normal)
        button.setTitleColor(UIColor.hexStringToColor(hexString: titleColorHighlighed), for: .highlighted)
        button.setTitleColor(UIColor.hexStringToColor(hexString: titleColorSelected), for: .selected)
        button.titleLabel?.font = UIFont.systemFont(ofSize: font)
        
        //图片相关
        button.setImage(UIImage(named: image), for: .normal)
        button.setImage(UIImage(named: imageHighlighted), for: .highlighted)
        
        //边框
        button.layer.borderColor = UIColor.hexStringToColor(hexString: borderColor).cgColor;
        button.layer.borderWidth = borderWidth;
        button.layer.cornerRadius = cornerRadius;
        button.layer.masksToBounds = masksToBounds;
        
        return button
    }
    
//    //Button背景图
//    [_addButton setBackgroundImage:[UIImage imageNamed:@"common_dashedroundcornered_12px_default.png" withTop:25 andLeft:5] forState:UIControlStateNormal];
//    [_addButton setBackgroundImage:[UIImage imageNamed:@"common_dashedroundcornered_12px_highlighted.png" withTop:25 andLeft:5] forState:UIControlStateHighlighted];
//    //Button文字
//    [_addOptionsButton setTitle:kLocalizedString(@"上传照片") forState:UIControlStateNormal];
//    [_addButton setTitleColor:kColor_b5b5b5 forState:UIControlStateNormal];
//    _addButton.titleLabel.font = kSize12;
//    [_addButton setTitleEdgeInsets:UIEdgeInsetsMake(0, 10/3, 0, 0)];
//    _aliButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
//    //上图下字的布局
//    _photoButton.titleEdgeInsets = UIEdgeInsetsMake(71, -_photoButton.bounds.size.width, 0, 0);//设置title在button上的位置（上top，左left，下bottom，右right）
//    //Button图片
//    [_addButton setImage:[UIImage imageNamed:@"fans_edit_location.png"] forState:UIControlStateNormal];
//    [_addButton setImageEdgeInsets:UIEdgeInsetsMake(0, 0, 0, 10/3)];

    
}

/**
 *  UITextField
 */
//MARK: - UITextField
extension UITextField {
    //把按钮直接不同属性的名字传进来，在这里我们传进来图片名字和标题
    class func creatTextField(font:CGFloat) -> UITextField {
        let textField = UITextField()
        textField.font = UIFont.systemFont(ofSize: font)
        textField.setValue(NSNumber(value: 12), forKey: "paddingLeft")

        
        textField.layer.borderColor = UIColor.hexStringToColor(hexString: "#666666").cgColor;
        textField.layer.borderWidth = 0.5;
        textField.layer.cornerRadius = 5;
        textField.layer.masksToBounds = true;
        return textField
    }
}

//MARK: - UIView

/**
 *  LineView
 */
extension UIView {
    //把按钮直接不同属性的名字传进来，在这里我们传进来图片名字和标题
    class func creatLineView(color: String) -> UIView {
        let lineView = UIView()
        lineView.backgroundColor = UIColor.hexStringToColor(hexString: color)
        return lineView
    }
}

//MARK: - UIBarButtonItem

/**
 *  leftBarButtonItem
 */
extension UIBarButtonItem {
    //把按钮直接不同属性的名字传进来，在这里我们传进来图片名字和标题
    class func creatLeftBarButtonItem(_ title: String,_ image: String,_ imageHighlighted: String, _ target: AnyObject, action: Selector) -> UIBarButtonItem {
        let button = UIButton()
        
        button.setTitle(title, for: .normal)
        button.setTitleColor(UIColor.black, for: .normal)
        button.sizeToFit()
        
        button.setImage(UIImage(named: image), for: .normal)
        button.setImage(UIImage(named: imageHighlighted), for: .highlighted)
        button.addTarget(target, action: action, for: .touchUpInside)
        
        return UIBarButtonItem.init(customView: button);
    }
}

